package br.com.spring.mvc.component;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import br.com.spring.mvc.dao.SimpleDAO;
import br.com.spring.mvc.entity.Simple;

@Component("simpleComponent")
public class SimpleComponent {

	@Autowired
	private SimpleDAO dao;
	
	public List<Simple> list(){
		return dao.loadAll();
	}
	
	public int save(Simple entity){
		return dao.save(entity);
	}
	
	public void delete(int id){
		dao.delete(id);
	}
	
	public Simple get(int id) throws Exception{
		Simple simple = dao.get(id);
		if(simple == null){throw new Exception("Problema ao recuperar registro!");}
		return simple;
	}
}
